//
//  SLWBMainTabBar.swift
//  SinaWeiBo
//
//  Created by 孙磊 on 15/9/29.
//  Copyright © 2015年 Sun. All rights reserved.
//

import UIKit

class SLWBMainTabBar: UITabBar {

    //改变tabItem的位置  大小
    //布局子视图方法
    override func layoutSubviews() {
        super.layoutSubviews()
        var index : CGFloat = 0
        let w = UIScreen.mainScreen().bounds.width / 5
        let h = self.bounds.height
        let frame = CGRectMake(0, 0, w, h)
        for btn in subviews{
            if btn is UIControl {
                btn.frame = CGRectOffset(frame, w * index, 0)
                if index == 1{
                    index++
                }
                index++
            }
        }
        midButton.frame = CGRectOffset(frame, 2 * w, 0)
        self.addSubview(midButton)
    }
    
    //懒加载中间按钮
    lazy var midButton:UIButton = {
        //创建一个按钮
        let btn = UIButton(type: UIButtonType.Custom)
        //添加按钮的图片
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        //添加按钮的背景图片
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState:UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        //返回按钮
        return btn
    }()//加（）是告诉编译器这个方法会被调用
}
